<?php
// +----------------------------------------------------------------------
// | Ocm [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace Portal\Controller;
use Common\Controller\HomebaseController; 
/**
 * 首页
 */
class IndexController extends HomebaseController {
	function _initialize() {
		parent::_initialize();
		$this->news_model = D("Common/News");
		$this->newsRoll_model = D("Common/NewsRoll");
	}
	public function Index(){
		$type = I("type","0");
		$this->redirect("Index/news/type/$type");
	}
    //首页
	public function news() {
		$this->_list(I("type"));
		$this->_newsRoll();
    	$this->display();
    }
	public function newsdetail(){
		$id=I("get.id");
		$model=$this->news_model->where("id=$id")->find();
		$this->assign('model',$model);
		$this->display();
	}
	/////////////
	private function _list($type=0) {
//	    $fields = array('name'=>array("field" =>"name","operator" =>"like"));
//	    $where_and = $this ->get_where_ands(IS_POST, $fields);
//	    $where = join(' and ', $where_and);
//	    $count = $this ->news_model -> where($where) ->count(1);
		if(empty($type)){
			$where="1=1";
		}else{
			$where="news_type_id=$type";
		}
	    $page = $this ->page(1, 20);
	    $this ->assign("Page", $page ->show('Admin'));
	    $this ->assign("current_page", $page ->GetCurrentPage());
	    $newsList = $this ->news_model->where($where)->order('create_time desc') ->limit($page ->firstRow.','.$page ->listRows) ->select();
	    $this ->assign('newsList', $newsList);
	}
	public function _newsRoll(){
		$newsRoll = $this->newsRoll_model->select();
		$this ->assign('newsRoll', $newsRoll);
	}
}


